<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2022/6/20
 * Time: 4:28 下午
 */

namespace app\api\controller\v33;

use app\api\controller\v13\Auth2;
use app\common\cachemodel\live\LiveBroadcastPreview;

/**
 * Class Live
 * @package app\api\controller\v33
 */
class Live extends Auth2
{
    /**
     * 直播预告列表
     */
    public function previewList()
    {
        $nowTime = time();
        $previewModel = new LiveBroadcastPreview();
        $data = $previewModel->getPreviewList();

        $prewviewData = [];//预告数据
        $liveingData = [];//直播中数据
        foreach ($data['data'] as $datum)
        {
            $tmp = $previewModel->launchStatus($this->user, $datum);
            //获取开播距离当前时间的时差
            $tmp['time_difference'] = abs($datum['live_start_time'] - $nowTime);
            $tmp['live_start_time'] = $datum['live_start_time'];
            if ($tmp['status'] === 1) //预告
            {
                //开播时间超过当前时间不展示
                if ($datum['live_start_time'] < $nowTime)
                {
                    continue;
                }
                $prewviewData[] = $tmp;
            }//直播中
            else
            {
                $liveingData[] = $tmp;
            }
        }
        if ($liveingData)
        {
            $liveingData = resort($liveingData, 'live_start_time', 'ASC');
        }
        if ($prewviewData)
        {
            $prewviewData = resort($prewviewData, 'live_start_time', 'ASC');
        }
        $res = array_merge($liveingData, $prewviewData);
        return show(config('code.success'), '获取成功', $res);
    }
}
